#coding:utf-8
import os
from glob import glob
from optparse import OptionParser

# img_path = 'test_youju_guangzhao'
# cwd = os.getcwd()
# names = glob(os.path.join(cwd, img_path, '*.jpg'))
# names = sorted(names)
# names = [n + '\n'  for n in names]
# names[-1] = names[-1].strip()
# f = open('getmap_sequence_youju_guangzhao.txt', 'w')
# f.writelines(names)
# f.close()

def parse_args():
    parser = OptionParser()
    parser.add_option('-p', '--path', dest='path', default = None, help="image path")
    parser.add_option('-s', '--save', dest='save', default = None, help="save file name")
    options, args = parser.parse_args()
    return options

if __name__ == "__main__":
    opts = parse_args()
    assert (opts.path is not None and opts.save is not None), 'must give -p and -s'
    #img_names = glob(os.path.join(opts.path, '*.jpg'))
    img_names = glob(os.path.join(os.path.abspath(opts.path), '*.jpg'))
    img_names = sorted(img_names)
    img_names  = [n + '\n' for n in img_names]
    img_names[-1] = img_names[-1].strip()
    f = open(opts.save, 'w')
    f.writelines(img_names)
    f.close()
